package com.nycreativity.elecreativity.entity

import com.baomidou.mybatisplus.annotation.TableField
import com.baomidou.mybatisplus.annotation.TableLogic
import com.baomidou.mybatisplus.extension.activerecord.Model
import com.nycreativity.elecreativity.entity.enums.IsDelEnum
import com.nycreativity.elecreativity.util.usersession.UserContext
import io.swagger.annotations.ApiModelProperty
import java.io.Serializable
import java.time.LocalDateTime

open class BaseEntity(
    /**
     * 创建者
     */
    @ApiModelProperty(value = "创建者")
    @TableField(select = false)
    open var creator: Long? = null,

    /**
     * 创建时间
     */
    @ApiModelProperty(value = "创建时间")
    @TableField(select = false)
    open var createTime: LocalDateTime? = null
) : Model<BaseEntity>(), Serializable {


    /**
     * 修改者
     */
    @ApiModelProperty(value = "修改者")
    @TableField(select = false)
    open var modifier: Long? = null

    /**
     * 修改时间
     */
    @ApiModelProperty(value = "创建时间")
    @TableField(select = false)
    open var modifyTime: LocalDateTime? = null

    /**
     * 是否删除
     */
    @TableField(select = false)
    @ApiModelProperty(value = "是否删除")
    open var isDel: Int? = null

    override fun toString(): String {
        return "creator=$creator, createTime=$createTime, modifier=$modifier, modifyTime=$modifyTime, isDel=$isDel"
    }

    fun create(): BaseEntity {
        this.createTime = LocalDateTime.now()
        this.creator = UserContext.get()?.id
        return this
    }

    fun modify(): BaseEntity {
        this.modifyTime = LocalDateTime.now()
        this.modifier = UserContext.get()?.id
        return this
    }


}
